package com.ruoyi.web.temu;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ruoyi.web.TemuFzProductRestriction.domain.TemuFzProductRestriction;
import com.ruoyi.web.TemuProductTraffic.domain.TemuProductTraffic;
import com.ruoyi.web.TemuSalesData.domain.TemuSalesData;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;


public class test {
    public static void main(String[] args) throws IOException {
        String json = new String(Files.readAllBytes(Paths.get("D:\\ds\\RuoYi-Vue-master (1)\\RuoYi-Vue-master\\ruoyi-admin\\src\\main\\resources\\data.txt")));
        JSONObject root = JSONUtil.parseObj(json);
        JSONObject result = root.getJSONObject("result");
        JSONArray salesDataVOList = result.getJSONArray("salesDataVOList");

        // 销量数据表
        List<TemuProductTraffic> list = new ArrayList<>();
        //辅助表
        List<TemuFzProductRestriction> fzlist = new ArrayList<>();
        for (int i = 0; i < salesDataVOList.size(); i++) {
            JSONObject item = salesDataVOList.getJSONObject(i);
            JSONObject basic = item.getJSONObject("productSkcBasicInfoVO");
            //fz填充
            TemuFzProductRestriction fzinfo = new TemuFzProductRestriction();
            fzinfo.img = basic.getStr("productSkcPicture");
            fzinfo.spuId = basic.getStr("productId");
            fzinfo.highPriceProductSearchLimit = item.getLong("highPriceProductSearchLimit");
            fzinfo.highPriceProductSearchLimitBeginTime = item.getDate("highPriceProductSearchLimitBeginTime");
            fzinfo.highPriceProductSearchLimitEndTime = item.getDate("highPriceProductSearchLimitEndTime");
            fzinfo.marketProductSearchLimitBeginTime = item.getDate("marketProductSearchLimitBeginTime");
            fzinfo.marketProductSearchLimitEndTime = item.getDate("marketProductSearchLimitEndTime");
            fzinfo.shortTermFlowGrowBeginTime = item.getDate("shortTermFlowGrowBeginTime");
            fzinfo.shortTermFlowGrowEndTime = item.getDate("shortTermFlowGrowEndTime");
            fzinfo.longTermFlowGrowBeginTime = item.getDate("longTermFlowGrowBeginTime");
            fzinfo.longTermFlowGrowEndTime = item.getDate("longTermFlowGrowEndTime");
            fzinfo.marketProductSearchLimitTag = item.getStr("marketProductSearchLimitTag");
            fzinfo.date = DateUtil.date();
            fzlist.add(fzinfo);
            /////
            JSONArray datalist = item.getJSONArray("confirmTrendList");
                for (Object dataitem : datalist) {
                    JSONObject datejson = JSONUtil.parseObj(dataitem);
                    TemuProductTraffic info = new TemuProductTraffic();
                    info.productName = basic.getStr("productName");
                    info.imgUrl = basic.getStr("productSkcPicture");
                    info.spuId = basic.getStr("productId");
                    info.day=datejson.getDate("day");
                    info.quantity=datejson.getInt("quantity");
                    info.confirmGoodsQuantity=item.getInt("confirmGoodsQuantity");
                    info.date= DateUtil.date();
                    list.add(info);
                }
            }
        System.out.println(list.toString());
        System.out.println(fzlist.toString());
        }
}